home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 11.7 KB | 318 lines | [TEXT/MPS ] |
- // UScriptableObject.h
- // Copyright © 1984-96 by Apple Computer, Inc. All rights reserved.
-
- #ifndef __USCRIPTABLEOBJECT__
- #define __USCRIPTABLEOBJECT__
-
- // MacApp
-
- #ifndef __MACAPPTYPES__
- #include "MacAppTypes.h"
- #endif
-
- #ifndef __UCLASSDESC__
- #include "UClassDesc.h"
- #endif
-
- // Toolbox
-
- #ifndef __OSA__
- #include <OSA.h>
- #endif
-
- #if qAttachable
- #ifndef __UOSASCRIPT__
- #include "UOSAScript.h"
- #endif
- #endif
-
-
- //----------------------------------------------------------------------------------------
- // Forward and external class declarations.
- //----------------------------------------------------------------------------------------
-
- class CAEDesc;
- class TAppleEvent;
- class TCommandHandler;
- class TScriptableObjectList;
- class TStream;
-
- //----------------------------------------------------------------------------------------
- // MScriptableObject: Definition of an object that responds to scripting appleevents.
- //----------------------------------------------------------------------------------------
-
- const long kAllProperties = -1; // Constant to get all properties when calling MScriptableObject:GetContents
-
- class MScriptableObject
- {
- MA_DECLARE_CLASS;
-
- public:
- DescType fOMClassID; // The object model class id.
- #if qAttachable
- COSAScriptCntPtr fOSAScript;
- #endif
-
- //----------------------------------------------------------------------------------------
- // Construction
- //----------------------------------------------------------------------------------------
- public:
- MScriptableObject();
- MScriptableObject(DescType myClassID);
-
- #if qAttachable
- virtual ~MScriptableObject();
- #endif
-
- //----------------------------------------------------------------------------------------
- // Object Description
- //----------------------------------------------------------------------------------------
-
- virtual DescType GetOMClass();
- // Override this to return something other than fOMClassID for the AppleEvent Object
- // Model class for this object.
-
- virtual DescType GetSpecifierForm();
- // Override this to return something other than formIndex.
-
- virtual Boolean MakeObjectSpecifier(CAEDesc& theObjectSpecifier,
- DescType preferredForm);
- // Creates an object specifier describing this object. This calls GetObjectProperty and
- // GetContainer to support formName, formAbsolutePosition, and formUniqueID.
- // You'll only need to override this method if you want to make other forms of
- // object specifiers.
-
- //----------------------------------------------------------------------------------------
- // Accessing Contained Objects
- //----------------------------------------------------------------------------------------
-
- virtual MScriptableObject* GetIndContainedObject(DescType desiredType,
- long index);
- // Returns an object contained within this one based on its absolute
- // position within the container. If you override this method to return
- // contained objects TObject::GetContainedObject will use this to get
- // one or more objects required by the different reference forms.
-
- virtual MScriptableObject* GetObjectsWithinRange(DescType desiredType,
- MScriptableObject* startBounds,
- MScriptableObject* endBounds);
- // Returns an object or list of objects contained within this one
- // that lie within the startBounds object and the endBounds object.
- // The default method assumes that the startBounds and endBounds objects
- // are of the desiredType.
- // You can override this to provide custom range access.
-
- virtual MScriptableObject* GetAdjacentObject(DescType desiredType,
- DescType position);
- // When the OSL resolves relative reference forms it first specifies an object
- // then asks that object for the one before or after it. This method returns
- // an object of the desiredType before or after it. The default implementation
- // does this by calling GetIndContainedObject for its container until it
- // finds itself, the gets the adjacent object by index. This only works if the
- // desiredType is the same as this object.
- // You can override this method by to provide custom access.
-
- virtual MScriptableObject* GetContainedObject(DescType desiredType,
- DescType selectionForm,
- const CAEDesc& selectionData);
- // Returns an object contained within this one. If the desiredType is a property
- // of this object, we create a TPropertyAccessor and return it.
- // Later on, the TPropertyAccessor can act on the properties of this object.
-
- virtual MScriptableObject* GetObjectsContainer();
- // Returns the object that contains this one.
-
- virtual long CountContainedObjects(DescType desiredType);
- // Override this to return a count of the number of objects contained within this one.
-
- virtual TScriptableObjectList* MakeNewMarkingList();
- // Returns a TScriptableObjectList to use for marking objects contained within this one.
-
- //----------------------------------------------------------------------------------------
- // Comparison
- //----------------------------------------------------------------------------------------
-
- virtual Boolean CompareScriptableObjects(DescType operation,
- const CAEDesc& thingToCompare);
- // Compares this object to something else. The default method does a simple
- // direct comparison.
-
- virtual Boolean CompareProperties(DescType whichProperty,
- DescType operation,
- const CAEDesc& thingToCompare);
- // Compares a property of this object to something else.
-
- //----------------------------------------------------------------------------------------
- // Handling AppleEvents
- //----------------------------------------------------------------------------------------
-
- virtual void DoAEOnContainedObjects(TScriptableObjectList* theObjectList,
- CommandNumber aCommandNumber,
- TAppleEvent* message,
- TAppleEvent* reply);
- // If a complex object specifier resolves into a group of objects, the object
- // containing them gets a chance to handle the AppleEvent for the group.
- // The default method handles the SetData event by creating a command to
- // change the properties of all the objects.
-
- virtual TCommandHandler* GetCommandContext(const CommandNumber aCommandNumber) const;
-
- #if qOptimizeSelfSendAevt
-
- virtual Boolean IsPendingAction(const CommandNumber aCommandNumber,
- const unsigned long actionID) const;
- #endif
-
- void HandleScriptCommand(CommandNumber aCommandNumber,
- TAppleEvent* message,
- TAppleEvent* reply);
- // Behaviors attached to the target object are given a chance to handle the event.
- // If the event is not handled by a behavior, DoScriptCommand is called.
-
- virtual void DoScriptCommand(CommandNumber aCommandNumber,
- TAppleEvent* message,
- TAppleEvent* reply);
- // Aftering resolving an object specifier into an object this method is called.
- // Based on the command number in the aCommandNumber it dispatches the event to
- // one of the Core event support routines defined below.
- // Override this method if this object supports events beyond the core suite.
-
- // Methods called for the core suite events.
-
- virtual void DoAEClone(TAppleEvent* message, TAppleEvent* reply);
-
- virtual void DoAEClose(TAppleEvent* message, TAppleEvent* reply);
-
- virtual void DoAECountElements(TAppleEvent* message, TAppleEvent* reply);
-
- virtual void DoAECreateElement(TAppleEvent* message, TAppleEvent* reply);
-
- virtual void DoAEDelete(TAppleEvent* message, TAppleEvent* reply);
-
- virtual void DoAEDoObjectsExist(TAppleEvent* message, TAppleEvent* reply);
-
- virtual void DoAEGetClassInfo(TAppleEvent* message, TAppleEvent* reply);
-
- virtual void DoAEGetEventInfo(TAppleEvent* message, TAppleEvent* reply);
-
- virtual void DoAEGetData(TAppleEvent* message, TAppleEvent* reply);
-
- virtual void DoAEGetDataSize(TAppleEvent* message, TAppleEvent* reply);
-
- virtual void DoAEMove(TAppleEvent* message, TAppleEvent* reply);
-
- virtual void DoAEOpen(TAppleEvent* message, TAppleEvent* reply);
-
- virtual void DoAEPrint(TAppleEvent* message, TAppleEvent* reply);
-
- virtual void DoAESave(TAppleEvent* message, TAppleEvent* reply);
-
- virtual void DoAESetData(TAppleEvent* message, TAppleEvent* reply);
-
- //----------------------------------------------------------------------------------------
- // Object Properties
- //----------------------------------------------------------------------------------------
-
- virtual Boolean GetContents(CAEDesc& theContents, const CAEDesc& desiredType,
- long propertyFlags = kAllProperties);
- // Returns the contents of this object.
-
- virtual void SetContents(const CAEDesc& theContents);
- // Sets the contents of this object. If theContents is an AERecord,
- // SetObjectProperty will be called for each property key.
-
- virtual Boolean GetObjectProperty(CAEDesc& thePropertyValue,
- DescType whichProperty,
- const CAEDesc& desiredType);
- // Gets property values for this object. Returns true if the property was available,
- // false if not.
-
- virtual void SetObjectProperty(const CAEDesc& thePropertyValue,
- DescType whichProperty);
- // Override this method to set property values for this object.
-
- virtual void GetSetPropertyInfo(DescType whichProperty,
- CommandNumber& aCommandNumber,
- Boolean& canUndo,
- Boolean& causesChange,
- TCommandHandler* &theContext);
- // When an AppleEvent is received that will set a property for this object a TSetPropertyCommand
- // will be created to do it. You can override this method to provide the command number and the
- // canUndo and causesChange flags for the command.
-
- void SetPropertiesFromEvent(TAppleEvent* theEvent);
- // Sets the properties of an object based on the data in the keyAEPropData parameter
- // of the event.
-
- //----------------------------------------------------------------------------------------
- // Attached Scripts
- //----------------------------------------------------------------------------------------
-
- #if qAttachable
-
- Boolean HasOSAScript();
- // Return TRUE if this object has a script attached.
-
- void FreeOSAScript();
- // Throws out the script attached to this object.
-
- void SetOSAScript(const CAEDesc& scriptDesc);
- // Attaches a script described in the scriptDesc
-
- void GetOSAScript(CAEDesc& scriptDesc,
- const CAEDesc& desiredType);
- // Returns the script attached to this object as the desiredType.
-
- virtual Boolean HandleOSAEvent(CommandNumber aCommandNumber,
- TAppleEvent* message,
- TAppleEvent* reply);
- // Gives an attached script a chance to handle an AppleEvent.
- // Returns TRUE if the script handled the event.
-
- void IdleOSAScript();
- // Gives an attached script idle time so its idle event handler can do some work.
- // Respects the script's fNextScriptIdle so you can call it as often as you like.
-
- void ReadOSAScript(TStream* aStream);
- // Reads an attached script from aStream.
-
- void WriteOSAScript(TStream* aStream, DescType asType);
- // Writes an attached script to aStream.
-
- #endif // qAttachable
-
- };
-
- //----------------------------------------------------------------------------------------
- // MDefaultScriptableObject: Definition of an object that responds to scripting appleevents.
- //----------------------------------------------------------------------------------------
-
- class MDefaultScriptableObject : public MScriptableObject
- {
- MA_DECLARE_CLASS;
-
- public:
-
- MDefaultScriptableObject();
- MDefaultScriptableObject(DescType myClassID);
-
- virtual ~MDefaultScriptableObject();
-
- virtual void DoScriptCommand(CommandNumber aCommandNumber,
- TAppleEvent* message,
- TAppleEvent* reply); // Override
-
- inline Boolean IsRecordingOn();
-
- protected:
-
- Boolean fRecording;
- };
-
- inline Boolean MDefaultScriptableObject::IsRecordingOn()
- {
- return fRecording;
- };
-
- #endif // __USCRIPTABLEOBJECT__
-